function [out,out2] = SMM_obj( Xi,Rho,Nu,M,W,targeted_moments,two_outputs )

[G,outMeanMom]      = G_fun( Xi,Rho,Nu,M );
G                   = G(targeted_moments);
outMeanMom          = outMeanMom(targeted_moments);
out                 = ( G' )*( W(targeted_moments,targeted_moments) )*( G );
if isnan(out)
    out             = 1e9;
end

if two_outputs == 1
    out2            = outMeanMom;
end

end

